$(function(){
	$("#loading-first").fadeOut(500);
	$.ajax({
		type:'post',
		url:'{:url("/unit/car/all")}',
		success:function(res){
			if(res.code==1){
				console.log(res)
				var carlist=`<option value=''>请选择车辆</option>`;
				for(var i=0;i<res.data.length;i++){
					if($('.car').data('carid')==res.data[i].car_id){
						carlist+=`<option selected value='${res.data[i].car_id}'>${res.data[i].number}</option>`
					}else{
						carlist+=`<option value='${res.data[i].car_id}'>${res.data[i].number}</option>`
					}
				}
				$('.car').html(carlist)
			}else{
				Err(res.msg)
			}
		},
		error:function(){
			Err('请求失败')
		}
	})
	$('.back').on('click',function(){
		window.location.href="{:url('unit/car/cost')}?type=2"
	});
	$('.delete-list').on('click',function(){
		popup(this,"{:url('delete')}");
		
	});
	$('.keep').on('click',function(){
		if($('select[name=car_id]').val()){
		{if $Think.get.refuel_record_id}
		sendForm($(this),1,window.location.href); 
		{else/}
		sendForm($(this),1,"{:url('unit/car/cost')}?type=2"); 
		{/if}
		}else{
			Err('请选择车辆')
		}
	});
	//点击添加图片
	$('button').on('click',function(){
		 	if($(this).data('type')=='file'){
		 		$(this).parent().find('input[type=file]').click()
		 	}
		});
			$('input[type="file"]').on('change',function(){
			if($(this).data('type')=='img'){
				var fil=$(this)[0].files[0];
				var that=this;
				var reader = new FileReader();
				reader.onload = function(evt) {
					$(that).closest('.file-w').find('.fileimg').attr('src',evt.target.result)
				}
				reader.readAsDataURL(fil);
			}
		});
	//全选
	$('.check-all').on('click',function(){
		checkall(this)
	});
	$('.check-list').on('click',function(){
		checkall(this)
	});
	//删除多个
	$(".delete-multiple").on('click',function(){
		popup(this,"{:url('delete')}");
	})
	
})
